package sword.T28;

import util.TreeNode;

/**
 * @Author: 18362
 * @Create: 2022-04-01 12:10:48 星期五
 */
class Solution {
    public boolean isSymmetric(TreeNode root) {
        if (root == null)
            return true;
        return equal(root.left, root.right);
    }

    private boolean equal(TreeNode leftRoot, TreeNode rightRoot) {
        if (leftRoot == null && rightRoot == null)
            return true;
        if (leftRoot == null || rightRoot == null)
            return false;
        if (leftRoot.val != rightRoot.val)
            return false;
        return equal(leftRoot.left, rightRoot.right) && equal(leftRoot.right, rightRoot.left);
    }
}